package com.mt.course.service.model;

import java.util.List;
import java.util.Map;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.github.pagehelper.PageHelper;
import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.course.entity.ExaminationWrongFeedbackEntity;
import com.mt.course.mapper.ExaminationWrongFeedbackEntityMapper;

@Component
public class ExaminationWrongFeedbackServiceModel {
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ExaminationWrongFeedbackServiceModel.class);

    @Autowired
    private ExaminationWrongFeedbackEntityMapper examinationWrongFeedbackEntityMapper;

    public ServiceResult<List<ExaminationWrongFeedbackEntity>> selectList(Map<String, Object> params,
        PagerInfo<?> pagerInfo) {
        Assert.notNull(this.examinationWrongFeedbackEntityMapper,
            "Property 'examinationWrongFeedbackEntityMapper' is required.");
        ServiceResult<List<ExaminationWrongFeedbackEntity>> result =
            new ServiceResult<List<ExaminationWrongFeedbackEntity>>();
        try {
            if (pagerInfo != null) {
                PageHelper.startPage(pagerInfo.getPageIndex(), pagerInfo.getPageSize());
            }

            result.setResult(this.examinationWrongFeedbackEntityMapper.selectList(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ExaminationWrongFeedbackServiceModel][selectList]：query selectList occur exception", e);
        }
        return result;
    }

    public ServiceResult<ExaminationWrongFeedbackEntity> selectInfo(Map<String, Object> params) {
        Assert.notNull(this.examinationWrongFeedbackEntityMapper,
            "Property 'examinationWrongFeedbackEntityMapper' is required.");
        ServiceResult<ExaminationWrongFeedbackEntity> result = new ServiceResult<ExaminationWrongFeedbackEntity>();
        try {
            result.setResult(this.examinationWrongFeedbackEntityMapper.selectByPrimaryKey(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ExaminationWrongFeedbackServiceModel][selectInfo]：query selectInfo occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> insert(ExaminationWrongFeedbackEntity examinationWrongFeedbackEntity) {
        Assert.notNull(this.examinationWrongFeedbackEntityMapper,
            "Property 'examinationWrongFeedbackEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.examinationWrongFeedbackEntityMapper.insert(examinationWrongFeedbackEntity);
            if (save > 0) {
                id = examinationWrongFeedbackEntity.getExaminationWrongFeedbackId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ExaminationWrongFeedbackServiceModel][insert]：query insert occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateRelate(ExaminationWrongFeedbackEntity examinationWrongFeedbackEntity) {
        Assert.notNull(this.examinationWrongFeedbackEntityMapper,
            "Property 'examinationWrongFeedbackEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save =
                this.examinationWrongFeedbackEntityMapper.updateByPrimaryKeySelective(examinationWrongFeedbackEntity);
            if (save > 0) {
                id = examinationWrongFeedbackEntity.getExaminationWrongFeedbackId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error(
                "[ExaminationWrongFeedbackServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer>
        updateByPrimaryKeySelective(ExaminationWrongFeedbackEntity examinationWrongFeedbackEntity) {
        Assert.notNull(this.examinationWrongFeedbackEntityMapper,
            "Property 'examinationWrongFeedbackEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save =
                this.examinationWrongFeedbackEntityMapper.updateByPrimaryKeySelective(examinationWrongFeedbackEntity);
            if (save > 0) {
                id = examinationWrongFeedbackEntity.getExaminationWrongFeedbackId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error(
                "[ExaminationWrongFeedbackServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> deleteByPrimaryKey(Integer examinationWrongFeedbackId) {
        Assert.notNull(this.examinationWrongFeedbackEntityMapper,
            "Property 'examinationWrongFeedbackEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            int save = this.examinationWrongFeedbackEntityMapper.deleteByPrimaryKey(examinationWrongFeedbackId);
            result.setResult(save);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error(
                "[ExaminationWrongFeedbackServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }
}
